package com.sl.biz.modular.cdc.service.impl;

import com.sl.biz.modular.cdc.controller.domain.request.CdcPropertiesConfigSaveRequest;
import com.sl.biz.modular.cdc.dao.domain.entity.CdcPropertiesConfigDO;
import com.sl.biz.modular.cdc.dao.service.CdcPropertiesConfigDaoService;
import com.sl.biz.modular.cdc.service.CdcPropertiesBizService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class CdcPropertiesBizServiceImpl implements CdcPropertiesBizService {

    private final CdcPropertiesConfigDaoService cdcPropertiesConfigDaoService;

    @Override
    public List<CdcPropertiesConfigDO> queryByCdcId(CdcPropertiesConfigDO jobConfigDO) {
        return cdcPropertiesConfigDaoService.queryByCdcId(jobConfigDO.getCdcId());
    }

    @Override
    public Boolean removeById(CdcPropertiesConfigDO cdcConfigDO) {
        return cdcPropertiesConfigDaoService.removeById(cdcConfigDO.getId());
    }

    @Override
    public Boolean save(CdcPropertiesConfigSaveRequest cdcConfigDO) {
        String cdcId = cdcConfigDO.getCdcId();
        List<CdcPropertiesConfigDO> properties = cdcConfigDO.getProperties();
        cdcPropertiesConfigDaoService.removeByCdcId(cdcId);

        for (CdcPropertiesConfigDO property : properties) {
            property.setCdcId(cdcId);
        }
        cdcPropertiesConfigDaoService.saveBatch(properties);
        return Boolean.TRUE;
    }


}
